<template>
  <el-drawer
    :title="showCheckList.checkTypeId | titleFilter"
    :visible.sync="visible"
    :before-close="handleClose"
    :size="size">

    <el-col :span="22" :offset="1">

      <el-row>
        <el-button
          v-if="recallBtn"
          type="danger"
          class="pan-btn danger-btn"
          @click="recall"
          size="mini">
          撤回结论
        </el-button>
        <el-button
          v-if="changeStandardBtn"
          type="danger"
          class="pan-btn danger-btn"
          @click="changeStandard"
          size="mini">
          修改标准
        </el-button>
        <el-button
          v-if="recallPassBtn"
          type="danger"
          class="pan-btn danger-btn"
          @click="recallPass"
          size="mini">
          撤回放行
        </el-button>
      </el-row>

      <el-form label-width="80px" size="mini">
        <el-form-item label="物料名称:" prop="productName">
          {{ showCheckList.productName }}
        </el-form-item>

        <el-form-item label="GMP编码:" prop="productGmp">
          {{ showCheckList.productGmp }}
        </el-form-item>

        <el-form-item label="货品规格:" prop="productSpec">
          <span v-html="showCheckList.productSpec"></span>
        </el-form-item>

        <el-form-item prop="batchNumPrefix">
          <span slot="label">批&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号:</span>
          {{ showCheckList.batchNumPrefix }}
        </el-form-item>

        <el-form-item label="请验部门:" prop="registCheckDepartmentName">
          {{ showCheckList.registCheckDepartmentName }}
        </el-form-item>

        <el-form-item prop="registCheckUserName">
          <span slot="label">请&nbsp;&nbsp;验&nbsp;&nbsp;人:</span>
          {{ showCheckList.registCheckUserName }}
        </el-form-item>

        <el-form-item label="请验日期:" prop="registCheckDate">
          {{ showCheckList.registCheckDate | changeTime }}
        </el-form-item>

        <el-form-item label="所有物料编码:" prop="checkLists">
          <el-button
            v-for="list in checkLists"
            :key="list.checkId"
            type="info"
            class="pan-btn info-btn"
            @click="showInnerDrawer(list)"
            size="mini">
            {{ list.batchNum + '(' + list.procedureName + ')' }}
          </el-button>
        </el-form-item>

        <check-info
          v-if="innerVisible"
          @close="handleInnerClose"
          @refreshData="init"
          :childDataForm="grandDataForm" />

      </el-form>
    </el-col>

    <change-standard
      v-if="changeStandardVisible"
      @close="close('changeStandardVisible')"
      :childDataForm="grandDataForm" />

  </el-drawer>
</template>

<script>
  import { isBlank,unique } from '@/common/js/utils'
  import { CODE_OK } from '@/common/js/config'
  import { isPositiveNumber } from '@/common/js/validate'
  import { getStandardByProductId } from '@/api/standard'
  import {
    getCheckInfo,
    getCheckListsByShowCheckId,
    recallVerdict,
    recallPass,
    getUpdateItemInfo,
    updateItemAfterDispense
  } from '@/api/check'
  import Calc from 'calculatorjs'
  import CheckInfo from './check-info'
  import ChangeStandard from '@/views/modules/common/change-standard'
  export default {
    components: {
    	CheckInfo,
      ChangeStandard
    },
    filters: {
      titleFilter(checkTypeId) {
        const titleMap = {
          4: '中间品请验单',
          5: '成品请验单'
        }
        return titleMap[checkTypeId]
      }
    },
    data() {
      return {
        size: '30%',
        visible: false,
        innerVisible: false,
        showCheckList: '',
        checkLists: [],
        grandDataForm: '',
        changeStandardVisible: false
      }
    },
    computed: {
      recallBtn() {
        //进入页面为结论菜单、请验单状态为未放行之前，允许撤回结论
        return this.childDataForm.currentStatus == 6 && (this.showCheckList.status == 7 || this.showCheckList.status == 10)
      },
      recallPassBtn() {
        //进入页面为放行菜单、请验单状态为放行之后（原辅包，成品(此页)），允许撤回放行
        return this.childDataForm.currentStatus == 7
          && this.c(this.showCheckList.checkTypeId)
          && (this.showCheckList.status == 8 || this.showCheckList.status == 11)
      },
      changeStandardBtn() {
        //进入页面为结论菜单、请验单状态为未结论之前，允许修改标准
        return this.childDataForm.currentStatus == 6
          && this.c(this.showCheckList.checkTypeId)
          && this.showCheckList.status <= 6
      }
    },
    props: ["childDataForm"],
    created() {
      if (!isBlank(this.childDataForm)) {
        this.showCheckList = this.childDataForm.info
        this.init()
      	this.visible = true
      }
    },
    methods: {
      changeStandard() {
        this.grandDataForm = {
          checkMergeId: this.showCheckList.checkMergeId,
          productId: this.showCheckList.productId,
          checkTypeId: this.showCheckList.checkTypeId
        }
        this.changeStandardVisible = true
      },
      recall() {
        //撤回结论
        const data = {
          checkId: this.showCheckList.checkId
        }
        recallVerdict(data).then(res => {
          if (res.code === CODE_OK) {
            this.$message({
              message: '提交成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.$emit('refreshData')
                this.handleClose()
              }
            })
          }else{
            this.$message.error(res.msg)
          }
        })
      },
      recallPass() {
        //测回放行
        const data = {
          checkMergeId: this.showCheckList.checkMergeId
        }
        recallPass(data).then(res => {
          if (res.code === CODE_OK) {
            this.$message({
              message: '提交成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.$emit('refreshData')
                this.handleClose()
              }
            })
          }else{
            this.$message.error(res.msg)
          }
        })
      },
      getCheckLists() {
        const params = {
          showCheckId: this.showCheckList.checkId
        }
        getCheckListsByShowCheckId(params).then(res => {
          if (res.code === CODE_OK) {
            this.checkLists = res.lists
          }else{
          	this.$message.error(res.msg)
          }
        })
      },
      init() {
        this.getCheckLists()
      },
      showInnerDrawer(list) {
        this.grandDataForm = {
          currentStatus: this.childDataForm.currentStatus,
          info: list
        }
        this.innerVisible = !this.innerVisible
      },
      handleInnerClose() {
        this.innerVisible = false
        this.grandDataForm = ''
      },
      close(prop) {
        this.grandDataForm = {}
        this[prop] = false
      },
      handleClose() {
        this.$emit('close')
        this.visible = false
      }
    }
  }
</script>

<style scoped>
  .el-form-item {
    margin-bottom: 0px !important;
  }
  >>> .el-form-item__content {
    line-height: 28px;
  }
</style>
